import { Component, director, Node, tween, UIOpacity, _decorator } from 'cc';

const { ccclass, property } = _decorator;

@ccclass('LoadingScene')
export class LoadingScene extends Component {
	@property(Node)
	bgNd: Node = null;

	start() {
		// 切换场景：加载-》显示
		// director.loadScene('Game');

		// 预加载场景
		director.preloadScene('Game', (error) => {
			if (error) {
				throw new Error(error.message);
			}

			tween(this.bgNd.getComponent(UIOpacity))
				.to(0.5, { opacity: 180 })
				.call(() => {
					director.loadScene('Game');
				})
				.start();
		});
	}
}
